package cn.edu.cjw.APMFP.ui.panel;

import cn.edu.cjw.APMFP.RoleRight.pojo.RoleRight;
import cn.edu.cjw.APMFP.Util.CacheUtil;
import cn.edu.cjw.APMFP.ui.CenterPanel;
import cn.edu.cjw.APMFP.ui.component.VFlowLayout;
import cn.edu.cjw.APMFP.user.pojo.User;

import javax.swing.*;
import java.awt.*;

/**
 * @package cn.edu.cjw.APMFP.ui.panel
 * @className PersonPanel
 * @note 个人面板
 * @author wind
 * @date 2022/3/12 13:12
 */
public class PersonPanel extends JPanel {

    private CenterPanel mainPanel;

    public PersonPanel(CenterPanel mainPanel) {
        this.mainPanel = mainPanel;
        init();
    }

    public void init(){
        User user = CacheUtil.getUser(mainPanel);
        this.setLayout(new BorderLayout(10, 10));
        JPanel personJPanel = new JPanel(new VFlowLayout(FlowLayout.CENTER, 10, 10));
        personJPanel.setBorder(BorderFactory.createTitledBorder("用户信息"));
        personJPanel.setPreferredSize(new Dimension(560, 220));
        this.add(personJPanel, BorderLayout.NORTH);
        JLabel label1 = new JLabel("账号：" + user.getAccount());
        JLabel label2 = new JLabel("昵称：" + user.getName());
        JLabel label3 = new JLabel("性别：" + user.getGender());
        JLabel label4 = new JLabel("年龄：" + user.getAge());
        personJPanel.add(label1);
        personJPanel.add(label2);
        personJPanel.add(label3);
        personJPanel.add(label4);

        RoleRight roleRight = user.getuRole();

        JPanel roleJPanel = new JPanel(new VFlowLayout(FlowLayout.CENTER, 10, 10));
        roleJPanel.setBorder(BorderFactory.createTitledBorder("角色信息"));
        roleJPanel.setPreferredSize(new Dimension(560, 220));
        this.add(roleJPanel, BorderLayout.CENTER);

        if(roleRight == null){
            return;
        }
        JLabel l1 = new JLabel("名称：" + roleRight.getRName());
        JLabel l2 = new JLabel("描述：" + roleRight.getRDescribe());
        JLabel l3 = new JLabel("权限：" + String.join(",", roleRight.getRRight()));
        roleJPanel.add(l1);
        roleJPanel.add(l2);
        roleJPanel.add(l3);
    }
}
